//
//  KDWebAddCell.m
//  PublicSentimentMonitorSystem
//
//  Created by 魏强 on 15/11/9.
//  Copyright © 2015年 魏强. All rights reserved.
//

#import "KDWebAddCell.h"
#import "KDWebSetCellModel.h"
@interface KDWebAddCell ()
@property (weak, nonatomic) IBOutlet UILabel *nameLb;
/**
 *  网址label
 */
@property (weak, nonatomic) IBOutlet UILabel *addressLb;
@property (weak, nonatomic) IBOutlet UIButton *shareBtn;
/**
 *  添加网站的勾选按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *addBtn;

@end
@implementation KDWebAddCell

- (void)awakeFromNib {
    // Initialization code
}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *cellId =@"KDWebAddCell";
    
    UINib *xib = [UINib nibWithNibName:@"KDWebAddCell" bundle:nil];
    [tableView registerNib:xib forCellReuseIdentifier:cellId];
    KDWebAddCell *cell =[tableView dequeueReusableCellWithIdentifier:cellId];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}
- (void)setModel:(KDWebSetCellModel *)model{
    _model = model;
    self.nameLb.text = model.websiteName;
    self.addressLb.text = model.desc;
    self.addBtn.selected = model.isAdd;
    self.shareBtn.selected = model.share;
    self.shareBtn.enabled = self.addBtn.selected;
    [self layoutIfNeeded];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
}
#pragma mark - 事件点击区


- (IBAction)addBtnClick:(UIButton *)sender {
    self.addBtn.selected = !self.addBtn.selected;
    self.model.add = self.addBtn.selected;
    self.shareBtn.enabled = self.addBtn.selected;
    if (_delegate && [_delegate respondsToSelector:@selector(KDWebAddCell:addBtnClickWithModel:)] ){
        
        [_delegate KDWebAddCell:self addBtnClickWithModel:self.model];
    }
    self.shareBtn.enabled = self.addBtn.selected;
}
- (IBAction)shareBtnClick:(UIButton *)sender {
    self.model.share = !self.model.share;
    self.shareBtn.selected = self.model.share;
    
    if (_delegate && [_delegate respondsToSelector:@selector(KDWebAddCell:shareBtnClickWithModel:)] ){
        [_delegate KDWebAddCell:self shareBtnClickWithModel:self.model];
    }
}


@end
